//
//  AddViewController.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 15/11/26.
//  Copyright © 2015年 周佳兴. All rights reserved.
//   上传照片、展示音频、图片 页面

#import "CustomizedAddViewController.h"
#import "ListDetailCell.h"
#import "CustomTextField.h"
#import "KeyNameClass.h"
#import "MyButton2.h"
#import "SexView.h"
#import "SelectSchoolController.h"
#import "OneSelectView.h"
#import "NSString+InputCheck.h"
#import "PickerTimeView.h"
#import "SelectManyView.h"
#import "PicAddListsViewController.h"
#import "KeyValuesClass.h"
#import "UILabel+StringFrame.h"
#import "postPicViewController.h"
#import "SetAddOrEditKindKeys.h"

#define SEX 16
@interface CustomizedAddViewController ()<UITextFieldDelegate,UITextViewDelegate>{
    
    CGFloat             delta;
    CustomTextView     *focusTextField;
    BOOL                added;
    UIView              *withShowPicView;
    SexView             *sexView;
    MyButton2           *sexBtn;
    BOOL                addSucceed;
    BOOL                editSucceed;
    
    EditModel           *selectModel; // 标记当前选中的 cell 中所属 MODEEEEEL
    
    
}
@property(nonatomic,retain)NSMutableArray               *filedArr;
@property(nonatomic,retain)NSMutableArray               *filedArrHomeWork;

@property(nonatomic,retain)NSMutableArray               *momentFiledArr;

@property(nonatomic,retain)UIAlertView           *alert;
@property(nonatomic,retain)UIAlertView           *alertSure;

@property(nonatomic,retain)OneSelectView         *oneSelectView;
@property(nonatomic,retain)SelectManyView        *SelectManyView;
//@property(nonatomic,assign)NSInteger             indexNum;
@property(nonatomic,retain)NSMutableArray        *mangManArr;
@property(nonatomic,retain)NSMutableArray        *mangManArrHomework;

@property(nonatomic,retain)NSMutableArray        *momentMangManArr; // 暂时          多安装


@property(nonatomic,retain)UIImageView           *backImg;
@property(nonatomic,retain)NSMutableArray        *textFieldArr;
@property(nonatomic,retain)UIImageView           *timeBackImg;
@property(nonatomic,retain)PickerTimeView        *pickerTime;
@property(nonatomic,retain)NSMutableArray        *defaultArr;
@property(nonatomic,retain)NSMutableDictionary   *selectedDic;   // 已输入的文字显示
@property(nonatomic,retain)NSMutableArray        *needElseChange;   // 已输入的文字显示
@property(nonatomic,retain)NSMutableArray        *conditionShow;   // 前提条件集成

@property(nonatomic,retain)NSString              *relationId;   // 关联添加Id

@property(nonatomic,retain)NSString              *relationIdHomework;   // 关联添加Id

@property(nonatomic,retain)NSMutableArray        *hiddenArr;

@property(nonatomic,retain)NSMutableArray        *hiddenArrHomework;

@property(nonatomic,retain)NSMutableDictionary   *addStyleEqualto3;

@property (strong, nonatomic)KeyValuesClass      *keyValueClass;
@property (nonatomic,assign)CGSize sizeaa;
@property(nonatomic,copy)NSString *picNAme;
@property(nonatomic,assign)NSInteger picNUm;
@property(nonatomic,strong)NSMutableDictionary *selectSchoolKeyValueDic; // 前提条件 Dic

@property(nonatomic,strong)UILabel *btn;
@property(nonatomic,strong)UILabel *la;

@end
@implementation CustomizedAddViewController

- (void) keyboardWillShow:(NSNotification *)notify {
    //    UIView *sv = focusTextField.superview;
    
    CGRect rectInTableView = [self.tbView rectForRowAtIndexPath:focusTextField.indexPath];
    CGRect rectInSuperview = [self.tbView convertRect:rectInTableView toView:[self.tbView superview]];
    CGFloat kbHeight = 256;//getKeyboardHeight(notify);
    // 取得键盘的动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    CGFloat screenHeight = self.view.bounds.size.height;
    //    [UIScreen mainScreen].bounds.size.height;
    
    CGFloat viewBottom = rectInSuperview.origin.y + rectInSuperview.size.height;
    
    if(!added){
        CGSize size = self.tbView.contentSize;
        size.height += 270;
        self.tbView.contentSize = size;
        added = YES;
    }
    
    if (viewBottom + kbHeight < screenHeight)return;
    
    // 键盘会盖住输入框, 要移动整个view了
    //    if (lastIndexPath.row<focusTextField.indexPath.row&&lastIndexPath!=nil) {
    //        delta += viewBottom + kbHeight - screenHeight;
    //
    //    }else{
    //    }
    delta = viewBottom + kbHeight - screenHeight;
    
    
    // masonry的地方了 mas_updateConstraints 更新superView的约束
    //    [self.tbView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(@(-delta-30));//.offset(50);
    //    }];
    CGPoint point = self.tbView.contentOffset;
    point.y += delta;
    [UIView animateWithDuration:duration animations:^void(void){
        // superView来重新布局
        self.tbView.contentOffset = point;
        [self.tbView layoutIfNeeded];
    }];
}

- (void) keyboardWillHidden:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //    [superView mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.top.equalTo(@(0));
    //    }];
    [self.tbView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
    }];
    [UIView animateWithDuration:duration animations:^{
        
        [self.tbView layoutIfNeeded];
    }];
    delta = 0.0f;
    if(added){
        CGSize size = self.tbView.contentSize;
        size.height -= 270;
        self.tbView.contentSize = size;
        added = NO;
    }
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.subBtn.enabled = YES;
    
    
    
}
-(void)viewDidLoad{
    [super viewDidLoad];
    _rowNum = 100000;
    NSString *btnType = [NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]];
    if(![btnType isEqualToString:@"12"]&&![btnType isEqualToString:@"15"]){
        _isAddPage = YES;
    }else{
        _isAddPage = NO;
    }
    self.tNum = 0;
    self.tString =[NSString stringWithFormat:@"t%li", (long)_tNum];
    
    _hiddenArr = [[NSMutableArray alloc]init];
    
    _hiddenArrHomework = [[NSMutableArray alloc]init];

    _needElseChange = [[NSMutableArray alloc]init];
    _conditionShow = [[NSMutableArray alloc]init];
    
    _filedArr = [[NSMutableArray alloc]init];
    
    _filedArrHomeWork = [[NSMutableArray alloc]init];

    _keyValueClass = [[KeyValuesClass alloc]init];
    
    _sendMutDic = [[NSMutableDictionary alloc]init];
    
    _sendMutDicHomeWork = [[NSMutableDictionary alloc]init];

    _mangManArr = [[NSMutableArray alloc]init];
    
    _mangManArrHomework = [[NSMutableArray alloc]init];

    _textFieldArr = [[NSMutableArray alloc]init];
    
    _selectedDic = [[NSMutableDictionary alloc]init];
    
    _addStyleEqualto3 = [[NSMutableDictionary alloc]init];
    
    OneSelectView *v = [[OneSelectView alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    [self.view addSubview:v];
    v.backgroundColor = [UIColor redColor];
    
    [self createUI];
    //    [self currDate];
    
    [self createLeftNavBar];
    [self createRightNavBar];
    [self dataRequest];
    NSLog(@"%@",_dicArr);
    _buttonDicHomeWork;
    NSString *strTitl = [NSString stringWithFormat:@"%@", [_buttonDic valueForKey:@"buttonName"]];
    //这里添加功能判断
    if (getEnglishLanguage()) {
        [self setTitleLabelText:@"End the Class"];
    }else{
#pragma mark - 按钮合一后的标题 建议单独设置
        [self setTitleLabelText:@"确认下课"];
    }
    
    NSNotificationCenter *noti = [NSNotificationCenter defaultCenter];
    [noti addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    NSNotificationCenter *noti1 = [NSNotificationCenter defaultCenter];
    [noti1 addObserver:self selector:@selector(keyboardWillHidden:) name:UIKeyboardWillHideNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(receiveSeleData:) name:@"schools" object:nil];
    _backImg =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
    [_backImg addGestureRecognizer:tap];
    
    [self.view addSubview:_backImg];
    _backImg.backgroundColor =[UIColor colorWithRed:30/255.0 green:32/255.0 blue:40 /255.0 alpha:0.5];
    [self.view bringSubviewToFront:_backImg];
    _backImg.hidden = YES;
    _backImg.userInteractionEnabled = YES;
}


-(void)tapClick{
    _oneSelectView.hidden = YES;
    _oneSelectView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
    _SelectManyView.hidden=YES;
    _SelectManyView.frame = CGRectMake(50, 1000, 200, 200);
    _SelectManyView.seleTitle = @"";
    
    
}

#pragma mark - 规则生成
-(void)whileHaveTmpFieldId:(EditModel *)model1 andBaseString:(NSString *)baseString andValue:(NSString *)baseValue{
    for (EditModel *model2 in _needElseChange) {
        
        if ([[NSString stringWithFormat:@"%@", model2.tmpFieldId]isEqualToString:[NSString stringWithFormat:@"%@", model1.fieldId]]) {
            
            NSLog(@"dic");
            
            
            [self requestNeedElse:model2 andBaseString:baseString andValue:baseValue];
        }
    }
}

-(void)requestNeedElse:(EditModel *)model andBaseString:(NSString *)baseString andValue:(NSString *)baseValue{
    
    
    
    NSMutableDictionary *parama = [[NSMutableDictionary alloc]init];
    [parama setObject:baseValue forKey:baseString];
    [parama setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
    [parama setObject:[_buttonDic valueForKey:@"tableId"] forKey:@"tableId"];
    
    NSString *requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, TMPREQUEST_URl];
    [NetRequest requestUrl:requestStr andParamas:parama andReturnBlock:^(NSData *data, NSError *error) {
        if (!error&&data!=nil) {
            
            NSString *str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            id obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            
            NSLog(@"%@", obj);
            if (str) {
                
                model.true_defaultShowValName = str;
                //                model.true_defaultShowValId = str;
                //                titleText.text = str;
                
                //                NSDictionary *dic= [_filedArr objectAtIndex:titleText.indexPath.row];
                //                NSString *fieldRole= [dic objectForKey:@"fieldRole"];
                //                NSString *fieldId= [dic objectForKey:@"fieldId"];
                //                NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
                //*** change the tableId
                //                NSString *tableId= [_buttonDic objectForKey:@"tableId"];
                //                NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@_%@",tableId,pageId,fieldId];
                NSString *role =[NSString stringWithFormat:@"%@",model.fieldRole];
                
                // NSString *baseString = [_keyValueClass makeTheBaseString:model andTheEditDic:_buttonDic]; // [self makeTheBaseString:dic]
                
                BOOL is = [NSString witchRoleis:role withStr:model.true_defaultShowValName];
                if(is){
                    
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName]; // [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]
                    NSLog(@"%@",_sendMutDic);
                    
                    //                    [_selectedDic setObject:titleText.text forKey:[NSString stringWithFormat:@"%ld", (long)titleText.indexPath.row]];
                }
            }
            
            [self.tbView reloadData];
        }else{
            NSString *string = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:string];
        }
    }];
}


#pragma mark receive data of schoolList
-(void)receiveSeleData:(NSArray *)arr{
    CustomTextField *titleText = (CustomTextField *)[self.view viewWithTag:1000+_rowNum];
    titleText.hidden = YES;
    //    titleText.backgroundColor =[UIColor greenColor];
    UILabel *titleLabel =(UILabel *)[self.view viewWithTag:2000+_rowNum];
    titleLabel.hidden = NO;
    
    NSString *titleStr;
    NSString *iDString;
    if(arr.count>1){
        
        titleStr = [arr[0] componentsJoinedByString:@","];
        iDString = [arr[1] componentsJoinedByString:@","];
    }else{
        titleStr = @"";
        iDString = @"";
    }
    EditModel *model;
    if (_rowNum>_filedArr.count-1&&_filedArrHomeWork.count>_rowNum-3) {
        model  = _filedArrHomeWork[_rowNum -3];
    }else if(_rowNum<_filedArr.count){
        model = _filedArr[_rowNum];
    }
    
    model.true_defaultShowValName = titleStr;
    model.true_defaultShowValId = iDString;
    //*** 键拼接 方法可能数据请求中也需要用 所以做了个简单的封装
    
    [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:self.tString andSendMutDic:_sendMutDic andManyMan:_mangManArr andEditDetailDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model211){
        _sendMutDic = send;
        //_mangManArr = manyman;
        _mangManArrHomework = manyman;
        _buttonDic = dicDEdit;
        //        [_fieldArrText replaceObjectAtIndex:_rowsNum withObject:model211];
    }];
    
    
    [self.tbView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:titleText.indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];
    
    
    
    NSString *baseString = [_keyValueClass makeTheBaseString:model andTheEditDic:_buttonDic]; // makeTheBaseString
    
    
    
    [self whileHaveTmpFieldId:model andBaseString:[KeyNameClass getKeyName:model.fieldRole andBaseString:baseString andTUseString:self.tString]andValue:model.true_defaultShowValId];
}


#pragma mark - reWrite function of fa class
-(void)createLeftNavBar{
    UIButton *leftNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftNavBtn.frame = CGRectMake(0, 0, 50, 37/2);
    //    [leftNavBtn setBackgroundImage:[UIImage imageNamed:@"形状1-19-拷贝-4"] forState:UIControlStateNormal];
    //这里添加功能判断
    if (getEnglishLanguage()) {
        [leftNavBtn setTitle:@"Cancel" forState:UIControlStateNormal];
        leftNavBtn.frame = CGRectMake(0, 0, 60, 37/2);
    }else{
        [leftNavBtn setTitle:@"取消" forState:UIControlStateNormal];
        leftNavBtn.frame = CGRectMake(0, 0, 50, 37/2);
    }
    [leftNavBtn addTarget:self action:@selector(LeftClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:leftNavBtn];
    self.navigationItem.leftBarButtonItem = item;
    
}

#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (alertView == _alertSure) {
        if(buttonIndex==1){
            if(_isAddPage){
                [self addRequestHomework];
            }else{
                [self editRequest];
            }
        }
        else{
            _alertSure.hidden = YES;
        }
        
        self.subBtn.enabled = YES;
        return;
    }
    NSLog(@"%ld",(long)buttonIndex);
    if(buttonIndex==0&&alertView==_alert){
        [self.navigationController popViewControllerAnimated:YES];
    }
    else if(alertView==_alert){
        _alert.hidden = YES;
    }
    
}

-(void)createRightNavBar{
    
    UIButton *rightNavBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    //这里添加功能判断
    if (getEnglishLanguage()) {
        rightNavBtn.frame = CGRectMake(0, 0, 65, 23);
    }else{
        rightNavBtn.frame = CGRectMake(0, 0, 50, 23);
    }

    
    [rightNavBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    //    [rightNavBtn setBackgroundImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
    [rightNavBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:rightNavBtn];
    //    self.navigat ionItem.leftBarButtonItem = item;
    NSString *str;
    
    
    
    
    
    
    
    
    if (_isAddPage) {
        if([_toString isEqualToString:@""]||_toString == nil){
            str = @"添加";
        }else{
            if ([_toString isEqualToString:@"Confirm"]) {
                rightNavBtn.frame = CGRectMake(0, 0, 65, 23);
            }
            str = self.toString;
        }
        
    }else{
        //            if (_isFromStudentMore) {
        str = @"submit";
        //            }else{
        //                str = @"提交";
        //            }
    }
    [rightNavBtn setTitle:str forState:UIControlStateNormal];
    self.subBtn = rightNavBtn;
    
    self.subBtn.hidden = YES;
    
    self.navigationItem.rightBarButtonItem = item;
    
}

-(void)rightClick:(UIButton *)btn{
    btn.enabled = NO;
    //    if(![focusTextField.text isEqualToString:@""]){
    //
    //        EditModel *model= [_filedArr objectAtIndex:focusTextField.indexPath.row];
    //
    //    NSString *fieldRole=[NSString stringWithFormat:@"%@", model.fieldRole];
    //
    //#warning maybe tableId not this
    //    NSString *role =[NSString stringWithFormat:@"%@",fieldRole];
    //    BOOL is = [NSString witchRoleis:role withStr:focusTextField.text];
    //    if(is){
    ////        NSString *str= [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString];
    ////        [_sendMutDic setObject:focusTextField.text forKey:[KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]];
    //        NSLog(@"%@",_sendMutDic);
    //    }
    //    else{
    //        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"请输入正确的格式" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
    //        [alert show];
    //        focusTextField.text  =@"";
    //        btn.enabled = YES;
    //
    //        return;
    //    }
    //    }
    
    if(focusTextField)[focusTextField resignFirstResponder]; // 验证必填项是否为空
    NSString *string = @"isok";
    
    for(EditModel *fModel in _textFieldArr){
        if (fModel.indexPath.row + 1 <= _filedArr.count) {
            _momentMutDic = _sendMutDic;
        }else{
            _momentMutDic = _sendMutDicHomeWork;
        }
        BOOL is = [_keyValueClass textExit:fModel andSendDic:_momentMutDic andMany:_mangManArr andTnum:_tNum];
        if(!is){
            
            string = @"notok";
            
        }
    }
    
    
    NSString *Tips;//提示
    NSString *requiredItem;//必填项
    NSString *requiredItemCellText;//必填项cell的提示语
    NSString *cancel;
    NSString *isOKStr;
    NSString *tipString;
    //这里添加功能判断
    if (getEnglishLanguage()) {
        Tips = @"Tips";
        requiredItem = @"Required Item";
        requiredItemCellText = @"You must fill in the required item";
        cancel = @"Cancel";
        isOKStr = @"OK";
        if (_toString.length>0&&_toString!=nil) {
            
            tipString = [NSString stringWithFormat:@"Are your sure to %@", _toString];
        }else{
            
            tipString = [NSString stringWithFormat:@"Are your sure to add"];
            
        }
    }else{
        Tips = @"提示";
        requiredItem = @"必填";
        requiredItemCellText = @"必填项不能为空";
        cancel = @"取消";
        isOKStr = @"确定";
        if (_toString.length>0&&_toString!=nil) {
            
            tipString = [NSString stringWithFormat:@"是否%@", _toString];
        }else{
            
            tipString = [NSString stringWithFormat:@"是否添加"];
            
        }
    }
    
    
    
    
    
    
    if([string isEqualToString:@"isok"]){
        _alertSure =[[UIAlertView alloc]initWithTitle:Tips message:tipString delegate:self cancelButtonTitle:cancel otherButtonTitles:isOKStr, nil];
        [_alertSure show];
    }
    else{
        _alertSure =[[UIAlertView alloc]initWithTitle:Tips message:requiredItemCellText delegate:self cancelButtonTitle:isOKStr otherButtonTitles:nil, nil];
        [_alertSure show];
        
        
    }
}


#pragma mark - ADDReq
-(void)addRequest{
    //    _sendMutDic = [[NSMutableDictionary alloc]init];
    //    NSDictionary *dic= [_filedArr objectAtIndex:focusTextField.indexPath.row];
    
    EditModel *model;
    if(focusTextField){
        
        
        if (focusTextField.indexPath.row + 1 <= _filedArr.count) {
            model = [_filedArr objectAtIndex:focusTextField.indexPath.row];
        }else{
            model = [_filedArrHomeWork objectAtIndex:focusTextField.indexPath.row-_filedArr.count];
        }
    }
    
    NSString *fieldRole=[NSString stringWithFormat:@"%@", model.fieldRole]; // [dic objectForKey:@"fieldRole"]
    
    if(focusTextField&&![fieldRole isEqualToString:@"21"]&&![fieldRole isEqualToString:@"20"]&&![fieldRole isEqualToString:@"22"]&&![fieldRole isEqualToString:@"19"]){
        if([[NSString stringWithFormat:@"%@", model.fieldRole] isEqualToString:@"16"]){  // fieldRole
            
        }
        else{
            
            if (focusTextField.indexPath.row + 1 <= _filedArr.count) {
                [_sendMutDic setObject:focusTextField.text forKey:model.montageName]; // [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]
            }else{
                [_sendMutDicHomeWork setObject:focusTextField.text forKey:model.montageName]; // [KeyNameClass getKeyName:fieldRole andBaseString:baseString andTUseString:self.tString]
                
            }
            model.true_defaultShowValName = focusTextField.text;
            //*** receive show
            //            [_selectedDic setObject:focusTextField.text forKey:[NSString stringWithFormat:@"%ld", (long)focusTextField.indexPath.row]];
            
        }
    }
    
    if (_hiddenArr.count>0) {
        
        [_keyValueClass setHiddens:_hiddenArr andSendDic:_sendMutDic andMana:_mangManArr andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman) {
            _sendMutDic = send;
            _mangManArr = manyman;
        }];   // setHiddenArr:_hiddenArr
        
        //        [self setHiddens];
    }
    [_sendMutDic setObject:userName() forKey:@"loginName"];
    [_sendMutDic setObject:passWord() forKey:@"password"];
    [_sendMutDic setObject:[self.buttonDic valueForKey:@"startTurnPage"] forKey:@"pageId"];
    [_sendMutDic setObject:[_buttonDic objectForKey:@"tableId"] forKey:@"tableId"];
    if (getSessionId()) {
        [_sendMutDic setObject: getSessionId() forKey:@"sessionId"];
    }
    
    [_sendMutDic setObject:@"1" forKey:@"source"];
    
    //*** keyStr
    
    NSString *pageId= [_buttonDic objectForKey:@"startTurnPage"];
    //*** change the tableId
    NSString *tableId= [_buttonDic objectForKey:@"tableId"];
    NSString *relationStr = [NSString stringWithFormat:@"t0_au_%@_%@_%@", tableId, pageId, self.relationId];
    
    if([[NSString stringWithFormat:@"%@", [_buttonDic valueForKey:@"buttonType"]]isEqualToString:@"18"]){  // 关联添加必须键因为不是关联添加默认值将不显示
        [_sendMutDic setObject:[_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]] forKey:relationStr];
    }
    [_mangManArr removeAllObjects];
    
    NSArray *keyArray = [_sendMutDic allKeys];
    for(int i=0;i<keyArray.count;i++){
        NSMutableDictionary *ddd = [[NSMutableDictionary alloc]init];
        [ddd setValue:[_sendMutDic objectForKey:keyArray[i]] forKey:keyArray[i]];
        [_mangManArr addObject:ddd];
        
    }
    //   pageId=1080&t0_au_119_1080=18&t0_au_119_1080_1424=&t0_au_119_1080_1425=2016-10-12&t0_au_119_1080_1426=&t0_au_119_1080_1427=&t0_au_119_1080_1454_file_many=&t0_au_119_1080_7175=%E7%8E%8B%E7%8E%89%E5%8F%8C&t0_au_119_1080_7176=%E5%88%9D%E4%B8%80%E8%AF%AD%E6%96%87%E5%9F%BA%E7%A1%80%2C%E5%88%9D%E4%B8%80%E6%95%B0%E5%AD%A6%E5%9F%BA%E7%A1%80%2C%E5%88%9D%E4%B8%80%E4%BD%9C%E6%96%87%E5%9F%BA%E7%A1%80%2C%E5%88%9D%E4%B8%80%E8%8B%B1%E8%AF%AD%E5%9F%BA%E7%A1%80&tableId=119
    //
    //    tableId=119&loginName=15101130931&t0_au_119_2352_1426=&pageId=2352&t0_au_119_2352_1427=&source=1&t0_au_119_2352=18&password=000000&t0_au_119_2352_1471_file_many=&t0_au_119_2352_1424=&t0_au_119_2352_1454_file_many=&t0_au_119_2352_1425=2016-10-12%2000:00:00
    NSString *str= [_keyValueClass fieldDicToString:_mangManArr isAdd:YES]; //[self fieldDicToString:_mangManArr];
    
    NSLog(@"%@",_sendMutDic);
    
    
    [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
    
    
    
    NSMutableString *lastUrl = [NSMutableString stringWithFormat:@"%@%@?%@",self.programaUrl, ADD_Commit_URL,str];
    
    
    if([lastUrl hasPrefix:@"http://182.92.74.232:9994"]){
        NSArray *arr = [lastUrl componentsSeparatedByString:@"182.92.74.232:9994"];
        lastUrl = [NSMutableString stringWithFormat:@"%@%@%@", arr[0], @"182.92.108.162:8124", arr[1]];
    }
    
    
    NSString * urlString= [lastUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url_str=[NSURL URLWithString:urlString];
    
    
    
    
    //    NSArray *arr = [_sendMutDic allKeys];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url_str];
    //    3.发送请求
    //发送异步请求，在主线程执行
    NSOperationQueue *queue=[NSOperationQueue mainQueue];
    
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if(data!=nil&&!connectionError){
            NSString *dataStr=  [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"dataString --------------------      %@ --------------------", dataStr);
            
#pragma mark - 登录超时返回登录页
            NSRange range = [dataStr rangeOfString:@"登录超时"];
            
            if (range.location != NSNotFound) {
                [self sessionIsOverTime:dataStr];
                return;
            }
#pragma mark - 登录超时end
            
//            if(![dataStr isEqualToString:@"0"]&&dataStr.length>0){// 不知道咋回事 之前 是 1 但是现在我感觉 不为 0 就行 返回的是 数据的条数
//                
//                [self addRequestHomework];
//            }
            
            
            NSString *Success;
            NSString *fail;
            NSString *str;
            //这里添加功能判断
            if (getEnglishLanguage()) {
                Success = @"Success";
                fail = @"Failed";
                str = @"Add";
            }else{
                Success = @"成功";
                fail = @"失败";
                str = @"添加";
            }
            if(![dataStr isEqualToString:@"0"]&&dataStr.length>0){// 不知道咋回事 之前 是 1 但是现在我感觉 不为 0 就行 返回的是 数据的条数
                
                //*** post the notifacation center should reload list view controller
                [[NSNotificationCenter defaultCenter]postNotificationName:@"shouldReload" object:@"ok"];
                
//                NSString *str = @"添加";
                if(![_toString isEqualToString:@""]||_toString != nil){
                    str = _toString;
                }
                
                _alert =[[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%@%@",str,Success] delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                
                self.subBtn.enabled = YES;
                addSucceed = YES;
                
                //*** hidden the netWork state activity
                [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
                
            }
            else{
//                NSString *str = @"添加";
                if(![_toString isEqualToString:@""]&&_toString!=nil){
                    str = _toString;
                }
                _alert =[[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%@%@",str,fail] delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                
                self.subBtn.enabled = YES;
                addSucceed = NO;
                
                //*** hidden the netWork state activity
                [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
                
            }
        }else{
            [self showLabelWithText:@"网络错误"];
            
            //*** hidden the netWork state activity
            [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
            
        }
    }];
    
}


#pragma mark - ADDReq
-(void)addRequestHomework{
    
    [_sendMutDicHomeWork setObject:userName() forKey:@"loginName"];
    [_sendMutDicHomeWork setObject:passWord() forKey:@"password"];
    [_sendMutDicHomeWork setObject:[self.buttonDicHomeWork valueForKey:@"startTurnPage"] forKey:@"pageId"];
    [_sendMutDicHomeWork setObject:[_buttonDicHomeWork objectForKey:@"tableId"] forKey:@"tableId"];
    if (getSessionId()) {
        [_sendMutDicHomeWork setObject: getSessionId() forKey:@"sessionId"];
    }
    
    [_sendMutDicHomeWork setObject:@"1" forKey:@"source"];
    
    //*** keyStr
    
    NSString *pageId= [_buttonDicHomeWork objectForKey:@"startTurnPage"];
    //*** change the tableId
    NSString *tableId= [_buttonDicHomeWork objectForKey:@"tableId"];
    NSString *relationStr = [NSString stringWithFormat:@"t0_au_%@_%@_%@", tableId, pageId, self.relationIdHomework];
    
    if([[NSString stringWithFormat:@"%@", [_buttonDicHomeWork valueForKey:@"buttonType"]]isEqualToString:@"18"]){  // 关联添加必须键因为不是关联添加默认值将不显示
        [_sendMutDicHomeWork setObject:[_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]] forKey:relationStr];
    }
    
    
    NSArray *keyArray = [_sendMutDicHomeWork allKeys];
    for(int i=0;i<keyArray.count;i++){
        NSMutableDictionary *ddd = [[NSMutableDictionary alloc]init];
        [ddd setValue:[_sendMutDicHomeWork objectForKey:keyArray[i]] forKey:keyArray[i]];
        [_mangManArrHomework addObject:ddd];
        
    }
    NSString *str= [_keyValueClass fieldDicToString:_mangManArrHomework isAdd:YES]; //[self fieldDicToString:_mangManArr];
    
    NSLog(@"%@",_sendMutDicHomeWork);
    
    
    [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:YES];
    
    
    
    NSMutableString *lastUrl = [NSMutableString stringWithFormat:@"%@%@?%@",self.programaUrl, ADD_Commit_URL,str];
    
    
    if([lastUrl hasPrefix:@"http://182.92.74.232:9994"]){
        NSArray *arr = [lastUrl componentsSeparatedByString:@"182.92.74.232:9994"];
        lastUrl = [NSMutableString stringWithFormat:@"%@%@%@", arr[0], @"182.92.108.162:8124", arr[1]];
    }
    
    
    NSString * urlString= [lastUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url_str=[NSURL URLWithString:urlString];
    
    
    
    
    //    NSArray *arr = [_sendMutDic allKeys];
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url_str];
    //    3.发送请求
    //发送异步请求，在主线程执行
    NSOperationQueue *queue=[NSOperationQueue mainQueue];
    
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if(data!=nil&&!connectionError){
            NSString *dataStr=  [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"dataString --------------------      %@ --------------------", dataStr);
            
#pragma mark - 登录超时返回登录页
            NSRange range = [dataStr rangeOfString:@"登录超时"];
            
            if (range.location != NSNotFound) {
                [self sessionIsOverTime:dataStr];
                return;
            }
#pragma mark - 登录超时end
            
            if(![dataStr isEqualToString:@"0"]&&dataStr.length>0){// 不知道咋回事 之前 是 1 但是现在我感觉 不为 0 就行 返回的是 数据的条数
                
                [self addRequest];
            }
            
            
            
            
            else{
                NSString *str = @"添加";
                if(![_toString isEqualToString:@""]&&_toString!=nil){
                    str = _toString;
                }
                _alert =[[UIAlertView alloc]initWithTitle:nil message:[NSString stringWithFormat:@"%@失败",str] delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                
                self.subBtn.enabled = YES;
                addSucceed = NO;
                
                //*** hidden the netWork state activity
                [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
                
            }
        }else{
            [self showLabelWithText:@"网络错误"];
            
            //*** hidden the netWork state activity
            [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
            
        }
    }];
    
}

-(void)editRequest{
    //    NSLog(@"%@",_schoolsArr);
    
    //    [self setHiddens];
    [_keyValueClass setHiddens:_hiddenArr andSendDic:_sendMutDic andMana:_mangManArr andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman) {
        _sendMutDic = send;
        _mangManArr = manyman;
    }];
    
    [_sendMutDic setObject:userName() forKey:@"loginName"];
    [_sendMutDic setObject:passWord() forKey:@"password"];
    if (getSessionId()) {
        [_sendMutDic setObject: getSessionId() forKey:@"sessionId"];
    }
    [_sendMutDic setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
    
    if (_isFromStudentMore) {
        NSDictionary *dic = [NSDictionary dictionaryWithDictionary:_sendMutDic];
        SaveTeacherInfo(dic);
        
    }
    
    
    NSString *t_str = [NSString stringWithFormat:@"T_%@_0",self.tableId];
    
    
    [_sendMutDic setObject:self.tableId forKey:@"tableId"];
    
    NSString *baseString = [NSString stringWithFormat:@"_au_%@_%@",[_buttonDic objectForKey:@"tableId"],[_buttonDic objectForKey:@"startTurnPage"]];
    
    [_sendMutDic setObject:[_detailDic objectForKey:t_str] forKey:[KeyNameClass getKeyName:@"1" andBaseString:baseString andTUseString:self.tString]];
    
    [_sendMutDic setObject: @"1" forKey:@"source"];
    
    NSArray *keyArray = [_sendMutDic allKeys];
    for(int i=0;i<keyArray.count;i++){
        NSMutableDictionary *ddd = [[NSMutableDictionary alloc]init];
        [ddd setValue:[_sendMutDic objectForKey:keyArray[i]] forKey:keyArray[i]];
        [_mangManArr addObject:ddd];
        
    }
    
    
    NSString *urlfieldAtr = [_keyValueClass fieldDicToString:_mangManArr isAdd:NO]; //[self fieldDicToString:_manyManyArr];
    
    NSString *lastUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, UPDATEMFSUB_URL];
    
    
    
    
    //*** hidden the netWork state activity
    
    
    NSString *lastUrl12 = [NSString stringWithFormat:@"%@?%@", lastUrl, urlfieldAtr];//[NSString stringWithFormat:@"%@?%@",requestStr,urlfieldAtr];
    
    if([lastUrl12 hasPrefix:@"http://182.92.74.232:9994"]){
        NSArray *arr = [lastUrl12 componentsSeparatedByString:@"182.92.74.232:9994"];
        lastUrl12 = [NSMutableString stringWithFormat:@"%@%@%@", arr[0], @"182.92.108.162:8124", arr[1]];
    }
    
    NSString * urlString= [lastUrl12 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url_str=[NSURL URLWithString:urlString];
    
    // NO
    
    
    NSLog(@"%@", lastUrl);
    
    
    NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url_str];
    //    3.发送请求
    //发送异步请求，在主线程执行
    NSOperationQueue *queue=[NSOperationQueue mainQueue];
    
    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        if(data!=nil&&!connectionError){
            
            NSString *dataStr=  [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            //            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            NSString *Success;
            NSString *fail;
            NSString *str;
            //这里添加功能判断
            if (getEnglishLanguage()) {
                Success = @"Success";
                fail = @"Failed";
                str = @"Modify";
            }else{
                Success = @"成功";
                fail = @"失败";
                str = @"修改";
            }
//            NSString *str = @"修改";
            if(![_toString isEqualToString:@""]||_toString != nil){
                str = _toString;
            }
            
#pragma mark - 登录超时返回登录页
            NSRange range = [dataStr rangeOfString:@"登录超时"];
            
            if (range.location != NSNotFound) {
                [self sessionIsOverTime:dataStr];
                return;
            }
#pragma mark - 登录超时end
            
            if(![dataStr isEqualToString:@"0"]&&dataStr.length>0){// 不知道咋回事 之前 是 1 但是现在我感觉 不为 0 就行 返回的是 数据的条数
                
                NSString *strEditResult = [NSString stringWithFormat:@"%@%@", str, Success];
                
                //*** post the notifacation center should reload list view controller
                [[NSNotificationCenter defaultCenter]postNotificationName:@"shouldReload" object:@"ok"];
                
                _alert =[[UIAlertView alloc]initWithTitle:nil message:strEditResult delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                
                editSucceed = YES;
                
                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                [[NSNotificationCenter defaultCenter]postNotificationName:@"changeSuccess" object:@"1"];
                
            }
            
            else{
                
                NSString *strEditResult = [NSString stringWithFormat:@"%@%@", str, fail];
                
                _alert =[[UIAlertView alloc]initWithTitle:nil message:strEditResult delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
                [_alert show];
                
                editSucceed = NO;
                
                [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(performDismiss:) userInfo:nil repeats:NO];
                
                
                //        NSTimer *time =[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:@selector(doTime) userInfo:nil repeats:NO];
                //[_sendMutDic removeAllObjects];
            }
            
            //*** hidden the netWork state activity
            [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
            
            
        }else{
            
            NSString *str = [NSString stringWithFormat:@"%@", connectionError.localizedDescription];
            [self showLabelWithText:str];
            //*** hidden the netWork state activity
            [[UIApplication sharedApplication]setNetworkActivityIndicatorVisible:NO];
            
        }
        
        
    }];
    
    
}


-(void) performDismiss:(NSTimer *)timer
{
    [_alert dismissWithClickedButtonIndex:0 animated:NO];
    if(addSucceed){
        if (self.retureView) {
            NSArray *arr = self.navigationController.viewControllers;
            
            for (id  viewController in arr) {
                if ([viewController isKindOfClass:[self.retureView class]]) {
                    [self.navigationController popToViewController:viewController animated:YES];
                    return;
                    
                }
            }
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
    if(editSucceed){
        if (self.retureView) {
            NSArray *arr = self.navigationController.viewControllers;
            
            for (id  viewController in arr) {
                if ([viewController isKindOfClass:[self.retureView class]]) {
                    [self.navigationController popToViewController:viewController animated:YES];
                    return;
                    
                }
            }
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
}
-(void)dataRequest{
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userName() forKey:@"loginName"];
    [parmas setObject:passWord() forKey:@"password"];
    
    NSString *path2;
    
    NSString *path3;
    
    NSDictionary *saveDic;
    
    
    
    NSString *requestStr;
    //    pageId=240&tableId=70&mainId=75&mainTableId=19&mainPageId=152
    
    NSString *btnType = [NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]];
    if(![btnType isEqualToString:@"18"]&&![btnType isEqualToString:@"12"]&&![btnType isEqualToString:@"15"]){
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, ADDMF_URL];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([self.buttonDic valueForKey:@"startTurnPage"])[parmas setObject:[self.buttonDic valueForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }else if([[NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]]isEqualToString:@"12"]||[[NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]]isEqualToString:@"15"]){
        [parmas setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        
        [parmas setObject:[_buttonDic valueForKey:@"tableId"] forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        [parmas setObject:@"2222211" forKey:@"alterTime"];
        
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, UPDATEMF_URL];
        
    }else{
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, RELATIONADD_URL];
        [parmas setObject:[_buttonDic objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:[_buttonDic valueForKey:@"tableId"] forKey:@"tableId"];
        
        [parmas setObject:self.tableId forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }
    
    [parmas setObject: getSessionId() forKey:@"sessionId"];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            
            self.subBtn.hidden = NO;
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            if ([obj valueForKey: @"promptMessage"]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
                
            }
            
            /*   SetAddOrEditKindKeys *setArrPreKeys = [[SetAddOrEditKindKeys alloc]init];
             [setArrPreKeys dataUse:obj andTnum:_tNum andtString:_tString andButtonDic:_buttonDic andReturnBlock:^(NSMutableDictionary *sendDic, NSMutableArray *manyArr, NSDictionary *buttonDic, NSMutableArray *hiddenArr, NSMutableArray *textFieldArr, NSMutableArray *fieldArr) {
             _sendMutDic = sendDic;
             _mangManArr = manyArr;
             _buttonDic = buttonDic;
             _hiddenArr = hiddenArr;
             _textFieldArr = textFieldArr;
             _filedArr = fieldArr;
             }];
             */
            // 数据处理，当没问题的情况下
            [self dataUse:obj];
            //            _itemDic = [obj valueForKey:@"dataInfo"];
            //            [self.tbView reloadData];
            
            [self dataRequestHomeWork];
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        //[self.tbView reloadData];
        
    }];
}

#pragma mark - Homework nei rong  get
-(void)dataRequestHomeWork{
    NSMutableDictionary *parmas = [[NSMutableDictionary alloc]init];
    [parmas setObject:userName() forKey:@"loginName"];
    [parmas setObject:passWord() forKey:@"password"];
    
    NSString *path2;
    
    NSString *path3;
    
    NSDictionary *saveDic;
    
    
    
    NSString *requestStr;
    //    pageId=240&tableId=70&mainId=75&mainTableId=19&mainPageId=152
    
    NSString *btnType = [NSString stringWithFormat:@"%@", [self.buttonDicHomeWork valueForKey:@"buttonType"]];
    if(![btnType isEqualToString:@"18"]&&![btnType isEqualToString:@"12"]&&![btnType isEqualToString:@"15"]){
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, ADDMF_URL];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([self.buttonDicHomeWork valueForKey:@"startTurnPage"])[parmas setObject:[self.buttonDicHomeWork valueForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }else if([[NSString stringWithFormat:@"%@", [self.buttonDicHomeWork valueForKey:@"buttonType"]]isEqualToString:@"12"]||[[NSString stringWithFormat:@"%@", [self.buttonDic valueForKey:@"buttonType"]]isEqualToString:@"15"]){
        [parmas setObject:[_buttonDicHomeWork objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:self.tableId forKey:@"tableId"];
        
        [parmas setObject:[_buttonDicHomeWork valueForKey:@"tableId"] forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        [parmas setObject:@"2222211" forKey:@"alterTime"];
        
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, UPDATEMF_URL];
        
    }else{
        requestStr = [NSString stringWithFormat:@"%@%@", self.programaUrl, RELATIONADD_URL];
        [parmas setObject:[_buttonDicHomeWork objectForKey:@"startTurnPage"] forKey:@"pageId"];
        [parmas setObject:[_buttonDicHomeWork valueForKey:@"tableId"] forKey:@"tableId"];
        
        [parmas setObject:self.tableId forKey:@"mainTableId"];
        [parmas setObject:self.pageId forKey:@"mainPageId"];
        
        [parmas setObject:[NSString stringWithFormat:@"%@", [_detailDic valueForKey:[NSString stringWithFormat:@"T_%@_0", self.tableId]]] forKey:@"mainId"];
        NSString *strTnum = [NSString stringWithFormat:@"%li", (long)_tNum];
        [parmas setObject:strTnum forKey:@"tNumber"];
        
        path2= myselfSaveFile(userName(), @"lists", @"lists.plist");
        
        path3 = [path2 stringByAppendingPathComponent:[NSString stringWithFormat:@"listForAdd%@%@.plist", self.tableId, self.pageId]];
        
        saveDic = [[NSDictionary alloc]initWithContentsOfFile:path3];
        
        if([saveDic valueForKey:@"alterTime"])
        {
            [parmas setObject:[saveDic valueForKey:@"alterTime"] forKey:@"alterTime"];
        }else{
            [parmas setObject:@"" forKey:@"alterTime"];
        }
        
    }
    
    [parmas setObject: getSessionId() forKey:@"sessionId"];
    
    [NetRequest requestUrl:requestStr andParamas:parmas andReturnBlock:^(NSData *data, NSError *error) {
        
        if(data!=nil&&!error){
            
            self.subBtn.hidden = NO;
            
            NSDictionary *obj = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            
            if ([obj valueForKey: @"promptMessage"]) {
                [[NSNotificationCenter defaultCenter]postNotificationName:@"relogin" object:@"relogin"];
                
            }
            
            /*   SetAddOrEditKindKeys *setArrPreKeys = [[SetAddOrEditKindKeys alloc]init];
             [setArrPreKeys dataUse:obj andTnum:_tNum andtString:_tString andButtonDic:_buttonDic andReturnBlock:^(NSMutableDictionary *sendDic, NSMutableArray *manyArr, NSDictionary *buttonDic, NSMutableArray *hiddenArr, NSMutableArray *textFieldArr, NSMutableArray *fieldArr) {
             _sendMutDic = sendDic;
             _mangManArr = manyArr;
             _buttonDic = buttonDic;
             _hiddenArr = hiddenArr;
             _textFieldArr = textFieldArr;
             _filedArr = fieldArr;
             }];
             */
            // 数据处理，当没问题的情况下
            [self dataUseHomework:obj];
            //            _itemDic = [obj valueForKey:@"dataInfo"];
            //            [self.tbView reloadData];
        }else{
            NSString *str = [NSString stringWithFormat:@"%@", error.localizedDescription];
            [self showLabelWithText:str];
            
        }
        
        [self.tbView reloadData];
        
    }];
}

-(BOOL)textView:(CustomTextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

-(void)createUI{
    self.tbView = [[UITableView alloc]init];
    [self.view addSubview:self.tbView];
    self.tbView.delegate = self;
    self.tbView.dataSource = self;
    self.tbView.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.tbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    
    
    withShowPicView = [[UIView alloc]init];
    withShowPicView.hidden = YES;
    [self.view addSubview:withShowPicView];
    withShowPicView.backgroundColor = [UIColor whiteColor];
    [withShowPicView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).offset(-49);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(342/2));
    }];
    
    _timeBackImg = [[UIImageView alloc]init];
    [self.view addSubview:_timeBackImg];
    [_timeBackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.view.mas_top);
        make.bottom.equalTo(withShowPicView.mas_top);
    }];
    _timeBackImg.alpha = 0.5;
    _timeBackImg.userInteractionEnabled = YES;
    _timeBackImg.backgroundColor = [UIColor blackColor];
    _timeBackImg.hidden = withShowPicView.hidden;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelClick)];
    [_timeBackImg addGestureRecognizer:tap];
    
    
    UIImageView *whichView = [[UIImageView alloc]init];
    whichView.image = [UIImage imageNamed:@"whitchB"];
    whichView.userInteractionEnabled = YES;
    [withShowPicView addSubview:whichView];
    [whichView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(withShowPicView.mas_top);
        make.left.equalTo(withShowPicView.mas_left);
        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(100/2));
    }];
    UIButton *cancelButton = [[UIButton alloc]init];
    //    cancelButton.backgroundColor = [UIColor blackColor];
    [whichView addSubview:cancelButton];
    [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(whichView.mas_centerY);
        make.left.equalTo(whichView.mas_left).offset(32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    [cancelButton setImage:[UIImage imageNamed:@"cancelNbUTTON"] forState:UIControlStateNormal];
    [cancelButton setImage:[UIImage imageNamed:@"cancelButton"] forState:UIControlStateSelected];
    UILabel *centerLabel = [[UILabel alloc]init];
    [whichView addSubview:centerLabel];
    [centerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.centerX.equalTo(whichView.mas_centerX);
        //        make.right.equalTo(withShowPicView.mas_right);
        //        make.height.equalTo(@(48/2));
    }];
    
    
    centerLabel.font = [UIFont systemFontOfSize:32/2];
    centerLabel.text = @"选择时间";
    centerLabel.textColor = [UIColor colorWithRed:0x74/255.0 green:0x75/255.0 blue:0x79/255.0 alpha:1];
    UIButton *okButton = [[UIButton alloc]init];
    [whichView addSubview:okButton];
    [okButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(cancelButton.mas_centerY);
        make.right.equalTo(whichView.mas_right).offset(-32/2);
        //        make.right.equalTo(withShowPicView.mas_right);
        make.height.equalTo(@(48/2));
    }];
    
    [okButton setImage:[UIImage imageNamed:@"okNButton"] forState:UIControlStateNormal];
    [okButton setImage:[UIImage imageNamed:@"okButotn"] forState:UIControlStateSelected];
    
    _oneSelectView = [[OneSelectView alloc]initWithFrame:CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200)];
    [self.view addSubview:_oneSelectView];
    ;
    _oneSelectView.delegateView = self;
    
    
    _SelectManyView =[[SelectManyView alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2-150, 40, 300, 300)];
    [self.view addSubview:_SelectManyView];
    ;
    _SelectManyView.delegateView = self;
    _SelectManyView.hidden = YES;
    
    
    self.pickerTime = [[PickerTimeView alloc]init];
    
    self.pickerTime.delegagte = self;
    [self.view addSubview:self.pickerTime];
    [self.pickerTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(self.view.mas_top);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    self.pickerTime.hidden = YES;
}

#pragma mark - dateReceiveData
-(void)picTimeReceive:(NSString *)dateStr{
    NSLog(@"%@", dateStr);
    
    EditModel *model = selectModel; // _filedArr[_rowNum];
    if (model.indexPath.row + 1 <= _filedArr.count) {
        _momentMutDic = _sendMutDic;
    }else{
        _momentMutDic = _sendMutDicHomeWork;
    }
    CustomTextField *titleText = (CustomTextField *)[self.view viewWithTag:1000+_rowNum];
    titleText.hidden = NO;
    NSString *str =[NSString stringWithFormat:@"%@", dateStr];
    titleText.text = str;
    
    model.true_defaultShowValName = str;
    
    NSString *baseString = [NSString stringWithFormat:@"%@", model.montageName];
    [_momentMutDic setObject:str forKey:baseString];
    NSLog(@"%@",_sendMutDic);
    if (model.indexPath.row + 1 <= _filedArr.count) {
        _sendMutDic  = _momentMutDic;
    }else{
        _sendMutDicHomeWork  = _momentMutDic;
    }
    self.pickerTime.hidden = YES;
    
    
    
}
#pragma mark - oneSelectBtn founction
-(void)leftBtnClick:(UIButton *)btn{
    
    _oneSelectView.hidden = YES;
    _oneSelectView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
    _SelectManyView.hidden = YES;
    _SelectManyView.frame = CGRectMake(50, 1000, [UIScreen mainScreen].bounds.size.width-100, 200);
    _backImg.hidden = YES;
    
}

#pragma mark - oneselectViewReturn Data
-(void)rightBtnClick:(UIButton *)btn{
    [self setNormalDataDic];
}

#pragma many ele
-(void)rightBtnClick1:(UIButton *)btn{
    
    [self setSeleManyDataDic];
    
}


-(void)sexBtn:(MyButton2 *)btn{
    sexBtn = btn;
}

#pragma mark - UITableViewCellDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _filedArr.count + _filedArrHomeWork.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    // 数据字典 ， 多选情况下 暂未做 判断 可参照 == 16 来做 切割
    EditModel *model;
    if (indexPath.row + 1 <= _filedArr.count) {
        model = _filedArr[indexPath.row];
    }else{
    model= _filedArrHomeWork[indexPath.row - _filedArr.count];
    }
    
    
    if([model.true_defaultShowVal containsString:@"png"]){
        
    }
    
    
    NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
    
#pragma - mark   *处理cell不同样式
    NSInteger num =[fieldRole integerValue];
    
    static NSString *listCell = @"listCell";
    ListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:listCell];
    if (cell == nil) {
        cell = [[ListDetailCell alloc]initWithReuseIdentifier:listCell];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell setEditIs:YES];
    //    NSDictionary *dic = [_filedArr objectAtIndex:indexPath.row];
    
    //    NSString *indexString = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
    model.indexPath  = indexPath;
    
    //    [dic setValue:indexString forKey:@"indexPath"];
    
    cell.title.text = model.fieldCnName; //[dic objectForKey:@"fieldCnName"];
    cell.titleText.delegate = self;
    NSString *mustStr = [NSString stringWithFormat:@"%@",model.ifMust];
    if( [mustStr isEqualToString:@"1"]){
        //这里添加功能判断
        if (getEnglishLanguage()) {
            cell.titleText.placeholder = @"Required Item";
        }else{
            cell.titleText.placeholder = @"必填";
        }

        cell.titleText.type = @"ismust";
        
    }else{
        cell.titleText.placeholder = @"";
        cell.titleText.type = @"";
        
    }
    
    cell.titleText.indexPath = indexPath;
    cell.titleText.tag = 1000+indexPath.row;
    cell.titleLabel.tag = 2000+indexPath.row;
    cell.titleText.delegate = self;
    
    
    
    //*** 可点 不可点          的跳转页面
    cell.titleText.tag = 1000+indexPath.row;
    BOOL canEditTextField = [_keyValueClass textCanEdit:num]; // num ==16||num == 14||num==28||num==26||num == 15||||num==20||num==21||num==22
    if (canEditTextField||model.tmpFieldId) { // 15 时间 14 日期15 数据字典  弹层
        
        cell.titleText.editable = NO;
        
        if (model.tmpFieldId) { // 需要规则生成
            for (EditModel *need in _needElseChange) {
                need.indexPathRow = [NSString stringWithFormat:@"%ld", (long)indexPath.row];
                
            }
        }
    }else if(model.fieldAliasName){
        if(_isAddPage){// 添加类型的页面有默认显示值不可编辑
            
            cell.titleText.editable = NO;
            cell.titleText.scrollEnabled = NO;
        }else if (!_isAddPage){//修改类型的页面都可编辑
            cell.titleText.editable = YES;
            cell.contentView.userInteractionEnabled = YES;
        }else{
            cell.titleText.editable = NO; // 是添加页 特殊字段 不可编辑
        }
        
    }else{
        cell.titleText.editable = YES;
    }
    
    //*** 左侧显示Label
    cell.title.text =[NSString stringWithFormat:@"%@:",model.fieldCnName];
    
    //    cell.title.text =[NSString stringWithFormat:@"%@:",[dic objectForKey:@"fieldCnName"]];
    
    cell.titleText.indexPath = indexPath;
    
    //*** right textFileld text
    NSString *cellTitleTextStringText;
    if(model.true_defaultShowValName&&num!=16&&num!=14&&num!=15&&num!=26&&num!=28&&num!=19){
        
        cellTitleTextStringText= [NSString stringWithFormat:@"%@", model.true_defaultShowValName];
    }else if(num == 16){
        NSArray *dataDicArr = [NSArray arrayWithArray:model.dicList]; // 取出数据字典中的值
        NSString *inter = [NSString stringWithFormat:@"%@", model.true_defaultShowValName]; // 默认值
        
        for (NSDictionary *dicDicList in dataDicArr) {
            {
                NSString *inter1 = [NSString stringWithFormat:@"%@", [dicDicList valueForKey:@"DIC_ID"]]; // 数据字典内值
                if([inter isEqualToString:inter1]){
                    cellTitleTextStringText = [NSString stringWithFormat:@"%@", [dicDicList valueForKey:@"DIC_NAME"]];
                }
            }
        }
        
    }else if(model.true_defaultShowValName&&(num==14||num==15||num==16||num==26||num==28)){
        
        cellTitleTextStringText = model.true_defaultShowValName; //[KeyValuesClass dateGlinToFormate:model.true_defaultShowValName]; // 由于时间格式返回的都是  格林尼治 所以 ····
    }else if (num == 19){
        //        if([model.true_defaultShowVal containsString:@":"]){
        //            NSArray *aa =[model.true_defaultShowVal componentsSeparatedByString:@":"];
        //            cellTitleTextStringText=aa[aa.count-1];
        //        }else{
        //          cellTitleTextStringText=model.true_defaultShowVal;
        //        }
        cellTitleTextStringText = [NSString stringWithFormat:@"%ld个",(long)_picNUm];
        cellTitleTextStringText = model.true_defaultShowValName;
        
        
        //        if(_btn==nil){
        //            _btn =[[UILabel alloc]init];
        //            [cell.contentView addSubview:_btn];
        //            [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        //                make.left.equalTo(cell.title.mas_right).offset(25);
        //                make.width.equalTo(@(100));
        //                make.height.equalTo(@(35));
        //                make.centerY.equalTo(cell.contentView.mas_centerY);
        //            }];
        //            [_btn setBackgroundColor:[UIColor colorWithHex:0x5da6ff]];
        //            _btn.layer.cornerRadius = 4.5;
        //            _btn.font =[UIFont systemFontOfSize:15];
        //            _btn.textColor =[UIColor whiteColor];
        //            _btn.layer.masksToBounds = YES;
        //            [_btn setText:@"点击拍照"];
        //            _btn.textAlignment = NSTextAlignmentCenter;
        //
        //        }
        //        if(_la==nil){
        //            _la =[[UILabel alloc]init];
        //            [cell.contentView addSubview:_la];
        //            [_la mas_makeConstraints:^(MASConstraintMaker *make) {
        //                make.left.equalTo(_btn.mas_right).offset(10);
        //                make.width.equalTo(@(100));
        //                make.height.equalTo(@(35));
        //                make.centerY.equalTo(cell.contentView.mas_centerY);
        //            }];
        //            _la.font =[UIFont systemFontOfSize:15];
        //            [_la setText:@"尚无附件"];
        //
        //        }
        
        if(cellTitleTextStringText!= nil){
            [cell.la setText:[NSString stringWithFormat:@"%ld",_picNUm]];
        }
        
        cell.titleText.text = @"333";
    }else{
        cellTitleTextStringText = @"";
    }
    
    
    
    cell.titleText.text = cellTitleTextStringText;
    if(indexPath.row==_rowNum){
        cell.titleText.hidden = YES;
        cell.titleLabel.hidden = NO;
        cell.titleLabel.text =cellTitleTextStringText;
    }
    
    if (num == 19){
        cell.titleLabel.hidden = YES;
        cell.titleText.hidden = YES;
        cell.btn.hidden= NO;
        cell.la.hidden= NO;
    }
    
    //*** 是否可更改 ， 也就是说回显
    
    if([[NSString stringWithFormat:@"%@", model.ifUpdate] isEqualToString:@"0"]||model.ifUpdate==nil){
        cell.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1];
        cell.titleText.editable = NO;
        if(num == 19){
            cell.btn.hidden= YES;
            cell.la.hidden= YES;
            cell.titleLabel.hidden = NO;
            //这里添加功能判断
            if (getEnglishLanguage()) {
                cell.titleLabel.text = @"NO Attachment";
                if (KWIDTH<400) {
                    _la.font = [UIFont systemFontOfSize:13];
                }else{
                    _la.font =[UIFont systemFontOfSize:15];
                }
            }else{
                cell.titleLabel.text = @"尚无附件";
            }
            cell.titleLabel.textColor = [UIColor colorWithHex:0x4c4c4c];
            
        }
    }else{
        cell.backgroundColor = [UIColor whiteColor];
    }
    NSLog(@"%ld",(long)num);
    return cell;
}

#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ListDetailCell *cell = (ListDetailCell *)[tableView cellForRowAtIndexPath:indexPath];
    if(focusTextField)[focusTextField resignFirstResponder];
    
    focusTextField = cell.titleText;
    
    EditModel *model;
    
    NSLog(@"%ld, %lu", (long)indexPath.row, (unsigned long)_filedArr.count);
    if (indexPath.row + 1 <= _filedArr.count) {
        model = [_filedArr objectAtIndex:indexPath.row];
        _momentMutDic = _sendMutDic;
    }else{
        model = [_filedArrHomeWork objectAtIndex:indexPath.row-_filedArr.count];
        _momentMutDic = _sendMutDicHomeWork;
    }
    NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
    NSInteger addStyle = [[NSString stringWithFormat:@"%@", model.addStyle] integerValue];
    
    //*** 前提条件
    if(model.jsWhereStr){
        
        NSString *is = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
        
        if (![is isEqualToString:@"YES"]) {
            
            [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", is]];
            
            return;
        }
    }
    NSInteger num =[fieldRole integerValue];
    
    
    selectModel = model;
    selectModel.indexPath = indexPath; // 指向当前选中的 Model 以防 后续使用时 重新识别
    if ((model.tmpFieldId||model.fieldAliasName)&&_isAddPage) { // 被其他的的的额大大神蛋白生成或默认 - 显示 - 的东西 return
        return;
    }
    if(([[NSString stringWithFormat:@"%@", model.ifUpdate] isEqualToString:@"0"]||!model.ifUpdate)){ // &&!_isAddPage 此处处理之前逻辑可能更改如有疑问 再改回来 ~~~~~~~
        return;
    }
    
    
    /**
     不同状况调不同方法
     */
    if(num == SEX){
        
        [self tableViewSelectDic:model];
        
    } else if (num == 17){//多选
        [self tableViewSelectDicMany:model];
        
        
    }else if(num == 14||num==28||num==26){
        [self tableViewSelectTimeType:model andIndexPath:indexPath];
        
    }else if(num == 15){ // 时间
        [self tableViewSelectTimeType:model andIndexPath:indexPath];
        
    }
    else if(num == 20||num == 21||num == 22){ //*** 下拉树  + 弹层
        
        if (addStyle == 3) { // 点击加号添加
            [self addStyle3:model andIndexPath:indexPath];
            
        }else if(addStyle == 2){
            
        }
        NSString *fieldRole =model.fieldRole; // [dic objectForKey:@"fieldRole"]
        NSInteger num =[fieldRole integerValue];
        if(num==21||num == 20||num==22){
            [self tableViewSelectAlertV:model andIndexPath:indexPath];
            
        }
        else{
        }
        
    }else if(num == 19){
        [self tableViewSelectPic:model];
    }
    else{
        [cell.titleText becomeFirstResponder];
    }
    
}


#pragma mark - 选择了照片
-(void)tableViewSelectPic:(EditModel *)model{
    postPicViewController * p = [[postPicViewController alloc]init];
    p.imgArrFromLastPage = model.postImgArr;
    p.LocalImgPathArr = model.postImgPathArr;
    NSLog(@"%@",p.imgArrFromLastPage);
    p.picID=^(NSMutableArray *arr, NSArray *imageArr ,NSMutableArray *localPathArr){
        NSLog(@"%@",arr);
        _picNUm = arr.count;
        
        model.true_defaultShowValName = [NSString stringWithFormat:@"%lu", (unsigned long)arr.count];
        NSMutableArray *IDArr =[[NSMutableArray alloc]init];
        NSMutableArray *nameArr =[[NSMutableArray alloc]init];
        for(NSString *sting in arr){
            
            NSArray *array =[sting componentsSeparatedByString:@":"];
            [IDArr addObject:array[1]];
            [nameArr addObject:array[2]];
            
        }
        
        NSString *picStrings = [IDArr componentsJoinedByString:@","];
        NSString *nameStr = [nameArr componentsJoinedByString:@","];
        model.true_defaultShowVal = nameStr;
        model.postImgArr = [NSMutableArray arrayWithArray:imageArr];
        model.postImgPathArr = localPathArr;
        if (model.indexPath.row + 1 <= _filedArr.count) {
            [_sendMutDic setObject:picStrings forKey:model.montageName];

        }else{
            [_sendMutDicHomeWork setObject:picStrings forKey:model.montageName];

        }
        [self.tbView reloadData];
        
    };
    [self.navigationController pushViewController:p animated:NO];
    
}
#pragma mark - 选择了弹出层 fieldRow == 20 21 22
-(void)tableViewSelectAlertV:(EditModel *)model andIndexPath:(NSIndexPath *)indexPath{
    
    NSString *fieldRole =model.fieldRole; // [dic objectForKey:@"fieldRole"]
    NSInteger num =[fieldRole integerValue];
    
    [_keyValueClass needFilterHave:model andManyManArr:_mangManArr andCurrentPageDataArr:_filedArr andTString:_tString detailDic:_detailDic andTableId:_tableId andSendDic:_sendMutDic andReturnBlock:^(NSMutableDictionary *filterDic,NSString *error) {
        if (!error) {
            _selectSchoolKeyValueDic = filterDic;
            
        }else{
            [self showLabelWithText:error]; // 前提条件未设置的情况下返回
            return;
        }
        
    }];
    SelectSchoolController *sv =[[SelectSchoolController alloc]init];
    sv.delegateView = self;
    
    if (num == 20) {
        sv.one = YES;
    }else{
        sv.one = NO;
    }
    if([[NSString stringWithFormat:@"%@", model.chooseType] isEqualToString:@"1"]){
        sv.treeDir = YES;
    }else{
        sv.treeDir = NO;
    }
    
    //*** premiseDic
    sv.premiseDic = _selectSchoolKeyValueDic;
    
    NSDictionary *d = model.dialogDataList; // objectForKey:@"dialogDataList"]; //[dic objectForKey:@"dialogDataList"];
    sv.schoolArr = [d objectForKey:@"rows"];
    
    NSString *requestUrl = [NSString stringWithFormat:@"%@%@", self.programaUrl, LISTSVIEWREQUEST_URL];
    
    sv.searchArr = model.dialogSearchSet; //[dic objectForKey:@"dialogSearchSet"];
    NSString *pageId= model.pageDialog; //[dic objectForKey:@"pageDialog"];
    NSString *tableId= model.tableId; //[dic objectForKey:@"tableId"];
    if(tableId == nil){
        tableId = model.relationTableId; //[dic objectForKey:@"relationTableId"];
    }
    sv.pageId = pageId;
    
    sv.tableId = tableId;
    
    sv.searchUrl = requestUrl;
    
    
    sv.schoolFieldStr = [NSString stringWithFormat:@"%@", model.tableId]; // [dic objectForKey:@"tableId"]
    sv.rowNum = indexPath.row;
    _rowNum = indexPath.row;
    
    [self.navigationController pushViewController:sv animated:YES];
    
}
#pragma mark - 选择了点击加号添加 add =    ==== 3
-(void)addStyle3:(EditModel *)model andIndexPath:(NSIndexPath *)indexPath{
    
    return;//点击加号添加不准用
    if (model.showFieldArr) { // pageId [dic valueForKey:@"showFieldArr"]
        
        PicAddListsViewController *picAddVC = [[PicAddListsViewController alloc]init];
        
        //*** 传送已添加的值
        if ([_addStyleEqualto3 valueForKey:[NSString stringWithFormat:@"%li", (long)indexPath.row]]) {
            picAddVC.defaultSourceArr = [_addStyleEqualto3 valueForKey:[NSString stringWithFormat:@"%li", (long)indexPath.row]];
        }
        
        picAddVC.tableId = [NSString stringWithFormat:@"%@", model.tableId]; // [dic valueForKey:@"tableId"]
        picAddVC.pageId = [NSString stringWithFormat:@"%@", model.showFieldArr]; // [dic valueForKey:@"showFieldArr"]
        picAddVC.fromDataArr = self.filedArr;
        picAddVC.fromMangManArr = self.mangManArr;
        picAddVC.fromSendMutDic = self.sendMutDic;
        picAddVC.delegateView = self;
        picAddVC.buttonDic = _buttonDic;
        picAddVC.tNum = _tNum;
        
        _rowNum = indexPath.row;
        
        NSLog(@"%@", picAddVC.fromDataArr);
        [self.navigationController pushViewController:picAddVC animated:YES];
        
    }
    
    return;
}
#pragma mark - 选择了时间格式的类型 fieldRow == 14
-(void)tableViewSelectTimeType:(EditModel *)model andIndexPath:(NSIndexPath *)indexPath{
    self.pickerTime.dataFormate = model.dateType;
    self.pickerTime.hidden = NO;
    self.pickerTime.datePicer.datePickerMode = UIDatePickerModeDate;
    _rowNum = indexPath.row;// for now else while be empany
    
}

#pragma mark - 选择了数据字典多选类型的 fieldRow == 18
-(void)tableViewSelectDicMany:(EditModel *)model{
    [self.view bringSubviewToFront:_backImg];
    _backImg.hidden = NO;
    [self.view bringSubviewToFront:_SelectManyView];
    [UIView animateWithDuration:0.5 animations:^{
        _SelectManyView.frame = CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 200);
    }];
    NSString *dicstr = [NSString stringWithFormat:@"%@", model.dicOptions];
    NSData *dicData = [dicstr dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *dicArr = [NSJSONSerialization JSONObjectWithData:dicData options:0 error:nil];
    _SelectManyView.dataArr = dicArr;
    _SelectManyView.hidden = NO;
    
}
#pragma mark - 选择了数据字典单选类型的  fieldRow == 16
-(void)tableViewSelectDic:(EditModel *)model{
    [UIView animateWithDuration:0.5 animations:^{
        _oneSelectView.frame = CGRectMake(50, 100, [UIScreen mainScreen].bounds.size.width-100, 200);
    }];
    NSString *strDicChildShow = [NSString stringWithFormat:@"%@", model.dicChildShow];
    
    NSArray *chilArr = [strDicChildShow componentsSeparatedByString:@","];
    NSArray *dicLArr = model.dicList;
    NSMutableArray *dicArr = [[NSMutableArray alloc]init];
    if(strDicChildShow.length>0){
        for (NSDictionary *dicElement in dicLArr) {
            NSString *strEleDic = [NSString stringWithFormat:@"%@", [dicElement valueForKey:@"DIC_ID"]];
            
            for (id obj in chilArr) {
                NSString *objStr = [NSString stringWithFormat:@"%@", obj];
                if ([strEleDic isEqualToString:objStr]) {
                    [dicArr addObject:dicElement];
                }
            }
        }
    }else{
        [dicArr addObjectsFromArray:dicLArr];
    }
    
#warning 可能要改
    _oneSelectView.dataArr = dicArr;
    withShowPicView.hidden = YES;
    _timeBackImg.hidden = withShowPicView.hidden;
    
    _oneSelectView.hidden = NO;
    
    if (focusTextField) {
        [focusTextField resignFirstResponder];
    }
    [self.view bringSubviewToFront:_oneSelectView];
    _backImg.hidden = NO;
    
}


#pragma mark - tableview 高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    EditModel *model;
    
    if (indexPath.row + 1 <= _filedArr.count) {
        model = _filedArr[indexPath.row];
    }else{
        model= _filedArrHomeWork[indexPath.row - _filedArr.count];
    }
    NSString *titleStr = [NSString stringWithFormat:@"%@", model.true_defaultShowValName];
    _sizeaa = [titleStr boundingRectWithSize:CGSizeMake(KWIDTH - 97, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size;
    if(_sizeaa.height<109/2){
        return _sizeaa.height+109/2;
    }else{
        return _sizeaa.height + 20;
    }
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(CustomTextField *)textField{
    
    focusTextField = textField;
    NSDictionary *dic = [_filedArr objectAtIndex:textField.indexPath.row];
    
    NSString *fieldRow = [dic valueForKey:@"fieldRole"];
    NSInteger num = [fieldRow integerValue];
    if (num == 6 || num == 7 || num == 12 || num == 13) {
        textField.keyboardType = UIKeyboardTypeNumberPad;
    }else{
        textField.keyboardType = UIKeyboardTypeDefault;
    }
}

-(void)textViewDidBeginEditing:(CustomTextView *)textView{
    focusTextField = textView;
    
    EditModel *model;
    if (textView.indexPath.row + 1 <= _filedArr.count) {
        model = [_filedArr objectAtIndex:textView.indexPath.row];
    }else{
        model = [_filedArrHomeWork objectAtIndex:textView.indexPath.row-_filedArr.count];
    }
    NSString *fieldRow = model.fieldRole;
    NSInteger num = [fieldRow integerValue];
    if (num == 6 || num == 7 || num == 12 || num == 13) {
        textView.keyboardType = UIKeyboardTypeNumberPad;
    }else{
        textView.keyboardType = UIKeyboardTypeDefault;
    }
}
#pragma mark - textField 即将开始 编辑处理
- (BOOL)textFieldShouldBeginEditing:(CustomTextField *)textField{
    //    NSDictionary *dic = [_filedArr objectAtIndex:textField.indexPath.row];
    EditModel *model;
    if (textField.indexPath.row + 1 <= _filedArr.count) {
        model = [_filedArr objectAtIndex:textField.indexPath.row];
        _momentFiledArr = _filedArr;
    }else{
        model = [_filedArrHomeWork objectAtIndex:textField.indexPath.row-_filedArr.count];
        _momentFiledArr = _filedArrHomeWork;
    }
    if(model.jsWhereStr){
        
        //        BOOL is = [self textQianTiTiaoJian:dic];
        
        NSString *is = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_momentFiledArr];
        
        if (![is isEqualToString:@"YES"]) {
            
            [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", is]];
            
            return NO;
        }
        
        return YES;
    }
    return YES;
}

-(BOOL)textViewShouldBeginEditing:(CustomTextView *)textView{
    //    NSDictionary *dic = [_filedArr objectAtIndex:textField.indexPath.row];
    EditModel *model;
    if (textView.indexPath.row + 1 <= _filedArr.count) {
        model = [_filedArr objectAtIndex:textView.indexPath.row];
        _momentFiledArr = _filedArr;
    }else{
        model = [_filedArrHomeWork objectAtIndex:textView.indexPath.row-_filedArr.count];
        _momentFiledArr = _filedArrHomeWork;
    }
    if(model.jsWhereStr){
        
        //        BOOL is = [self textQianTiTiaoJian:dic];
        
        NSString *is = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_momentFiledArr];
        
        if (![is isEqualToString:@"YES"]) {
            
            [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", is]];
            
            return NO;
        }
        
        return YES;
    }
    return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    return YES;
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    
    
    return NO;
}

-(void)nromalSetKeyValues:(EditModel *)model andTextField:(CustomTextView *)textField{
    
    NSString *fieldRole= [NSString stringWithFormat:@"%@", model.fieldRole];
    
    NSString *role =[NSString stringWithFormat:@"%@",fieldRole];
    BOOL is = [NSString witchRoleis:role withStr:textField.text];
    if(is){
        
        if (textField.indexPath.row + 1 <= _filedArr.count) {
            [_sendMutDic setObject:textField.text forKey:model.montageName]; // [self getNorMalKey:dic]
            NSLog(@"%@",_sendMutDic);
        }else{
            [_sendMutDicHomeWork setObject:textField.text forKey:model.montageName]; // [self getNorMalKey:dic]
            NSLog(@"%@",_sendMutDic);
        }
        model.true_defaultShowValName = textField.text;
        
        
    }
    else{
        UIAlertView *alert =[[UIAlertView alloc]initWithTitle:nil message:@"请输入正确的格式" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
        [alert show];
        textField.text  =@"";
    }
    
}


-(void)textViewDidEndEditing:(CustomTextView *)textView{
    if(![textView.text isEqualToString:@""]){
        
        //        NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
        
        EditModel *model;
        if (textView.indexPath.row + 1 <= _filedArr.count) {
            model = [_filedArr objectAtIndex:textView.indexPath.row];
        }else{
            model = [_filedArrHomeWork objectAtIndex:textView.indexPath.row-_filedArr.count];
        }
        [self nromalSetKeyValues:model andTextField:textView];
        
    }
}

-(void)textFieldDidEndEditing:(CustomTextField *)textField{
    if(![textField.text isEqualToString:@""]){
        
        //        NSDictionary *dic= [_filedArr objectAtIndex:textField.indexPath.row];
        
        EditModel *model;
        if (textField.indexPath.row + 1 <= _filedArr.count) {
            model = [_filedArr objectAtIndex:textField.indexPath.row];
        }else{
            model = [_filedArrHomeWork objectAtIndex:textField.indexPath.row-_filedArr.count];
        }
        
        [self nromalSetKeyValues:model andTextField:textField];
        
    }
    
}

-(void)receiveAddData:(NSMutableDictionary *)dic1{
    NSDictionary *receiveSendDic = [dic1 valueForKey:@"sendD"];
    NSArray *receiveMangMan = [dic1 valueForKey:@"mangManD"];
    NSArray *sendsMan = [dic1 valueForKey:@"sends"];
    NSArray *showsArr = [dic1 valueForKey:@"shows"];
    NSArray *source = [dic1 valueForKey:@"source"];
    
    [_sendMutDic setValuesForKeysWithDictionary:receiveSendDic];
    
    NSMutableArray *manymanArr = [[NSMutableArray alloc]initWithArray:_mangManArr];
    
    for (NSDictionary *dicM in manymanArr) {
        
        NSArray *arr1 = [dicM allKeys];
        for (NSDictionary *dicR in receiveMangMan) {
            NSArray *arr2 = [dicR allKeys];
            if (arr1 == arr2) {
                [_mangManArr removeObject:dicM];
            }
        }
    }
    [_mangManArr addObjectsFromArray:receiveMangMan];
    
    EditModel *model= [_filedArr objectAtIndex:_rowNum];
    
    NSString *fieldRole= [NSString stringWithFormat:@"%@", model.fieldRole];
    
    NSString *fieldId;
    if(model.relationTableId!=nil){
        if(model.dialogField){
            
            fieldId= [NSString stringWithFormat:@"%@", model.dialogField];
        }else{
            fieldId= [NSString stringWithFormat:@"%@", model.fieldId];
        }
    }else{
        fieldId= [NSString stringWithFormat:@"%@", model.fieldId];
        
    }
    
#warning maybe difernt tableId to use it for a moment
    
    //NSString *baseString = [_keyValueClass makeTheBaseString:model andTheEditDic:_buttonDic];
    
    NSString *relationTableId=[NSString stringWithFormat:@"%@",model.relationTableId] ;
    NSString *showFieldArr=[NSString stringWithFormat:@"%@",model.showFieldArr];
    
    NSString *fieldOfNum;
    
    fieldOfNum=[NSString stringWithFormat:@"%@", model.montageName];
    
    NSString *fieldOfValue =[NSString stringWithFormat:@"t%i_au_%@_%@_%@", _tNum+1,relationTableId,showFieldArr,fieldId];
    
    NSInteger num =[fieldRole integerValue];
    
    if(num == 22||num == 20){
        
    }else if(num == 21){
        NSMutableArray *muArr = [[NSMutableArray alloc]initWithArray:_mangManArr];
        
        for(NSDictionary *dict in _mangManArr){
            if([[dict allKeys] containsObject:fieldOfValue]||[[dict allKeys] containsObject:fieldOfNum]){
                [muArr removeObject:dict];
            }
        }
        _mangManArr = muArr;
        
        
        NSInteger arrNUm = [receiveMangMan count];
        
        NSMutableDictionary *dad = [[NSMutableDictionary alloc]init];
        [dad setObject:[NSString stringWithFormat:@"%ld",(long)arrNUm/2] forKey:fieldOfNum];
        [_mangManArr addObject:dad];
        NSLog(@"%@", _mangManArr);
    }
    
    for (NSDictionary *dicSArr in sendsMan) {
        NSArray *keyArray = [dicSArr allKeys];
        for(int i=0;i<keyArray.count;i++){
            NSMutableDictionary *ddd = [[NSMutableDictionary alloc]init];
            [ddd setValue:[dicSArr objectForKey:keyArray[i]] forKey:keyArray[i]];
            [_mangManArr addObject:ddd];
            
        }
        
    }
    
    
    NSString *str = [showsArr componentsJoinedByString:@","];
    
    NSString *keyString = [NSString stringWithFormat:@"%li", (long)focusTextField.indexPath.row];
    [_addStyleEqualto3 setObject:source forKey:keyString];
    focusTextField.text = str;
    [_selectedDic setObject:str forKey:[NSString stringWithFormat:@"%li", (long)focusTextField.indexPath.row]];
    
}


#pragma mark - UIImagePickerControllerDelegate 获取 文件拍照上传 获取文件拍照上传
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    //headImageView.image = image;
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
    
    
    
    
    //[btn2 setBackgroundImage:image forState:UIControlStateNormal];
    
    
    
    
}


#pragma mark - 正常字段设置数据字典 正常字段设置数据字典比较简单 就没做封装
-(void)setNormalDataDic{
    if(_oneSelectView.seleTitle !=nil){
        _oneSelectView.frame = CGRectMake(50, 1000, 200, 200);
        
        EditModel *model= selectModel;
        
        
        if (model.indexPath.row + 1<= _filedArr.count) {
            _momentMutDic = _sendMutDic;
            _momentMangManArr = _mangManArr;
            _momentButtonDic = _buttonDic;
        }else{
            _momentMutDic = _sendMutDicHomeWork;
            _momentMangManArr = _mangManArrHomework;
            _momentButtonDic = _buttonDicHomeWork;
            
        }
        
        [_momentMutDic setObject:_oneSelectView.seleTitleNum forKey:model.montageName];
        model.true_defaultShowValName = _oneSelectView.seleTitleNum;
        
        //*** receive show
        _oneSelectView.seleTitle = @"";
        
        NSLog(@"%@",_momentMutDic);
        
        for (EditModel *model in _conditionShow) {
            NSString *isN = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
            
            if (![isN isEqualToString:@"YES"]) {
                
                [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", isN]];
                
                return;
            }
            
            BOOL is;
            
            if ([isN isEqualToString:@"YES"]) {
                is = YES;
            }else{
                is = NO;
            }
            
            if (!is) {
                
                [_keyValueClass removeAlready:model andTstring:_tString andManyManyArr:_momentMangManArr andTnumBer:_tNum andSendMutDic:_momentMutDic andEditDic:_momentButtonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, EditModel *model) {
                    _momentMutDic = send;
                    _momentMangManArr = manyman;
                    
                }];
                model.true_defaultShowValName = @"";
                model.true_defaultShowValId = @"";
            }
        }
        
        if (model.indexPath.row + 1<= _filedArr.count) {
            _sendMutDic = _momentMutDic;
            _mangManArr = _momentMangManArr;
        }else{
            _sendMutDicHomeWork = _momentMutDic;
            _mangManArrHomework = _momentMangManArr;
        }
        [self.tbView reloadData];
        
    }
    _oneSelectView.hidden=YES;
    _backImg.hidden = YES;
    
}

#pragma mark - 正常字段设置数据字典 正常字段设置数据字典比较简单 就没做封装
-(void)setSeleManyDataDic{
    if(_SelectManyView.seleTitle !=nil){
        _SelectManyView.frame = CGRectMake(50, 1000, 200, 200);
        
        EditModel *model= selectModel;
        
        
#warning ttableId may not this
        [_sendMutDic setObject:_SelectManyView.seleTitleNum forKey:model.montageName];
        model.true_defaultShowValName = _SelectManyView.seleTitleNum;
        
        //*** receive show
        _SelectManyView.seleTitle = @"";
        
        NSLog(@"%@",_sendMutDic);
        
        for (EditModel *model in _conditionShow) {
            
            NSString *isN = [_keyValueClass textQianTiTiaoJian:model andTstring:_tString andFieldArr:_filedArr];
            
            if (![isN isEqualToString:@"YES"]) {
                
                [self showLabelWithText:[NSString stringWithFormat:@"请先选择%@", isN]];
                
                return;
            }
            
            BOOL is;
            
            if ([isN isEqualToString:@"YES"]) {
                is = YES;
            }else{
                is = NO;
            }
            
            if (!is) {
                
                [_keyValueClass removeAlready:model andTstring:_tString andManyManyArr:_mangManArr andTnumBer:_tNum andSendMutDic:_sendMutDic andEditDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, EditModel *model) {
                    _sendMutDic = send;
                    _mangManArr = manyman;
                    
                }];
                model.true_defaultShowValName = @"";
                model.true_defaultShowValId = @"";
            }
        }
        
        [self.tbView reloadData];
        
    }
    _SelectManyView.hidden=YES;
    _backImg.hidden = YES;
    
}



#pragma mark - 数据处理
-(void)dataUse:(id)obj{
    
    //***jsonModel 数据处理 , 如果键值对有所改变 ， 那么就将 model 内的 内容进行更改，注意 使用时的问题 ， cellForrowInThePath
    //    _conditionShow = [[NSMutableArray alloc]init];
    
    if([obj objectForKey:@"pageSet"]){
        
        self.relationId = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]]; // 将关联添加的 relationId 取出来 ， 如果要是关联添加的话，就可以直接使用关联添加的Id
        
        NSArray *dataArr = [[obj objectForKey:@"pageSet"]valueForKey:@"fieldSet"];
        for (NSDictionary *dic in dataArr) {
            EditModel *model = [[EditModel alloc]init];
            model = [model initWithDictionary:dic error:nil];
            NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.fieldRole];
            //             NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.ifShowDefVal];wewe
            
            NSString *stringUpdate = [NSString stringWithFormat:@"%@", model.ifUpdate];
            NSString *stringDefault = [NSString stringWithFormat:@"%@", model.dicDefaultSelect];
            
            // 数据字典类型
            if ([modelDefaultValueChange isEqualToString:@"16"]&&![stringUpdate isEqualToString:@"0"]&&stringDefault.length>0) {
                
                model.true_defaultShowValName = model.dicDefaultSelect;
            }else if([modelDefaultValueChange isEqualToString:@"16"]&&stringDefault.length>0){
                model.true_defaultShowValName = model.dicDefaultSelect;
            }
            [_filedArr addObject:model];
            if (model.jsWhereStr) { // 查看是否有启用禁用条件
                [_conditionShow addObject:model];
            }
            if (model.tmpFieldId) {
                [_needElseChange addObject:model];
            }
            
            
            
            
            NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
            NSInteger num =[fieldRole integerValue];
            // 拼接上传值
            if(num == 20 || num == 21 || num == 22){// 弹层 下拉树 内部对象
                
                //                [self whileFieldRowTypeIsspeciall:model];
                
                [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:_tString andSendMutDic:_sendMutDic andManyMan:_mangManArr andEditDetailDic:_buttonDic andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model){
                    _sendMutDic = send;
                    _mangManArr = manyman;
                    _buttonDic = dicDEdit;
                }];
            }else if(num == 14||num==28||num==26|| num == 15){ // 时间格式的 使用 14 年月日 ， 15 时分秒
                //                NSDateFormatter *formate = [[NSDateFormatter alloc]init];
                if(num == 15&&!model.dateType){
                    model.dateType = TIMEFORMATE;
                }else{
                    //model.dateType = DATEFORMATE;
                }
                if(model.true_defaultShowValName&&[model.true_defaultShowValName hasSuffix:@"000"]){
                    model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                    
                }else if(model.true_defaultShowValName){
                    //model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                }else{
                    [_sendMutDic setObject:@"" forKey:model.montageName];
                }
                
                
            }else if(num!=-1){
                
                if(model.true_defaultShowValName){
                    [_sendMutDic setObject:model.true_defaultShowValName forKey:model.montageName];
                }else{
                    [_sendMutDic setObject:@"" forKey:model.montageName];
                }
                
            }else if(num == -1){ // 占位 以防出现更多的 -1 状况
                NSString *strTimeDefault = [NSString stringWithFormat:@"%@", model.true_defaultShowValName];// 时间格式下找出web端是以 000 为结尾的格式显示 ， 在未找出 更合适的 方式之前 暂时用这个方式
                
                if([strTimeDefault hasSuffix:@"000"]){
                    if(model.true_defaultShowValName){
                        model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                        
                    }
                    
                }
            }
            
            //*** 必填项存储
            NSString *mustStr = [NSString stringWithFormat:@"%@",model.ifMust];
            if( [mustStr isEqualToString:@"1"]){
                [_textFieldArr addObject:model];
            }
        }
        NSArray *arrHiddenText = [[obj objectForKey:@"pageSet"]valueForKey:@"hideFieldSet"];
        
        for (NSDictionary *dic in arrHiddenText) {
            EditModel *model = [[EditModel alloc]init];
            model = [model initWithDictionary:dic error:nil];
            [_hiddenArr addObject:model];
        }
        
        [self.tbView reloadData];
    }
}

#pragma mark - 数据处理
-(void)dataUseHomework:(id)obj{
    
    //***jsonModel 数据处理 , 如果键值对有所改变 ， 那么就将 model 内的 内容进行更改，注意 使用时的问题 ， cellForrowInThePath
    //    _conditionShow = [[NSMutableArray alloc]init];
    
    if([obj objectForKey:@"pageSet"]){
        
        self.relationIdHomework = [NSString stringWithFormat:@"%@", [[obj objectForKey:@"pageSet"] valueForKey:@"relationFieldId"]]; // 将关联添加的 relationId 取出来 ， 如果要是关联添加的话，就可以直接使用关联添加的Id
        
        NSArray *dataArr = [[obj objectForKey:@"pageSet"]valueForKey:@"fieldSet"];
        for (NSDictionary *dic in dataArr) {
            EditModel *model = [[EditModel alloc]init];
            model = [model initWithDictionary:dic error:nil];
            NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.fieldRole];
            //             NSString *modelDefaultValueChange = [NSString stringWithFormat:@"%@", model.ifShowDefVal];wewe
            
            NSString *stringUpdate = [NSString stringWithFormat:@"%@", model.ifUpdate];
            NSString *stringDefault = [NSString stringWithFormat:@"%@", model.dicDefaultSelect];
            
            // 数据字典类型
            if ([modelDefaultValueChange isEqualToString:@"16"]&&![stringUpdate isEqualToString:@"0"]&&stringDefault.length>0) {
                
                model.true_defaultShowValName = model.dicDefaultSelect;
            }else if([modelDefaultValueChange isEqualToString:@"16"]&&stringDefault.length>0){
                model.true_defaultShowValName = model.dicDefaultSelect;
            }
            [_filedArrHomeWork addObject:model];
            
            
            
            
            NSString *fieldRole =[NSString stringWithFormat:@"%@", model.fieldRole];
            NSInteger num =[fieldRole integerValue];
            // 拼接上传值
            if(num == 20 || num == 21 || num == 22){// 弹层 下拉树 内部对象
                
                //                [self whileFieldRowTypeIsspeciall:model];
                
                [_keyValueClass whileFieldRowTypeIsspeciall:model andTnum:_tNum andTstring:_tString andSendMutDic:_sendMutDicHomeWork andManyMan:_mangManArrHomework andEditDetailDic:_buttonDicHomeWork andReturnBlock:^(NSMutableDictionary *send, NSMutableArray *manyman, NSDictionary *dicDEdit, EditModel *model){
                    _sendMutDicHomeWork = send;
                    _mangManArrHomework = manyman;
                    _buttonDicHomeWork = dicDEdit;
                }];
            }else if(num == 14||num==28||num==26|| num == 15){ // 时间格式的 使用 14 年月日 ， 15 时分秒
                //                NSDateFormatter *formate = [[NSDateFormatter alloc]init];
                if(num == 15&&!model.dateType){
                    model.dateType = TIMEFORMATE;
                }else{
                }
                if(model.true_defaultShowValName&&[model.true_defaultShowValName hasSuffix:@"000"]){
                    model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                    [_sendMutDicHomeWork setObject:model.true_defaultShowValName forKey:model.montageName];
                    
                }else if(model.true_defaultShowValName){
                    [_sendMutDicHomeWork setObject:model.true_defaultShowValName forKey:model.montageName];
                }else{
                    [_sendMutDicHomeWork setObject:@"" forKey:model.montageName];
                }
                
                
            }else if(num!=-1){
                
                if(model.true_defaultShowValName){
                    [_sendMutDicHomeWork setObject:model.true_defaultShowValName forKey:model.montageName];
                }else{
                    [_sendMutDicHomeWork setObject:@"" forKey:model.montageName];
                }
                
            }else if(num == -1){ // 占位 以防出现更多的 -1 状况
                NSString *strTimeDefault = [NSString stringWithFormat:@"%@", model.true_defaultShowValName];// 时间格式下找出web端是以 000 为结尾的格式显示 ， 在未找出 更合适的 方式之前 暂时用这个方式
                
                if([strTimeDefault hasSuffix:@"000"]){
                    if(model.true_defaultShowValName){
                        model.true_defaultShowValName = [KeyValuesClass dateGlinToFormate:model.true_defaultShowValName andFromate:model.dateType]; // 由于时间格式返回的都是  格林尼治 所以 ····
                        
                    }
                    
                }
            }
            
            //*** 必填项存储
            NSString *mustStr = [NSString stringWithFormat:@"%@",model.ifMust];
            if( [mustStr isEqualToString:@"1"]){
                [_textFieldArr addObject:model];
            }
        }

        
        [self.tbView reloadData];
    }
}



@end
